package com.zone.vehicle.superapp.repository;

import com.zone.sdk.common.http.base.Result;
import com.zone.sdk.common.http.callback.ResultCallBack;
import com.zone.sdk.module.account.entity.CaptchaCertExchangeEntity;
import com.zone.sdk.module.account.entity.CaptchaGetEntity;
import com.zone.sdk.module.account.entity.CheckCaptchaEntity;
import com.zone.sdk.module.account.entity.LoginEntity;
import com.zone.sdk.module.account.entity.LoginStatusEntity;
import com.zone.sdk.module.account.entity.QrLoginEntity;
import com.zone.sdk.module.account.entity.QrLoginPollEntity;
import com.zone.sdk.module.account.entity.UserInfoEntity;
import com.zone.sdk.module.account.request.UserInfoRequest;
import com.zone.sdk.module.account.response.CaptchaGetResponse;
import com.zone.vehicle.superapp.datasource.LoginDataSource;

/**
 * Class that requests authentication and user information from the remote data source and
 * maintains an in-memory cache of login status and user credentials information.
 */
public class LoginRepository {

    private static volatile LoginRepository instance;

    private LoginDataSource dataSource;

    // private constructor : singleton access
    private LoginRepository(LoginDataSource dataSource) {
        this.dataSource = dataSource;
    }

    public static LoginRepository getInstance(LoginDataSource dataSource) {
        if (instance == null) {
            instance = new LoginRepository(dataSource);
        }
        return instance;
    }


    public void login(String username, String password, String captcha_certificate, ResultCallBack<Result<LoginEntity>> callback) {
        dataSource.login(username, password, captcha_certificate, callback);
    }

    public void captchaGet(ResultCallBack<CaptchaGetResponse<CaptchaGetEntity>> callback){
        dataSource.captchaGet(callback);
    }
    /**
     * 三方安全校验
     */
    public void checkCaptcha(double sliderXMoved, String token, String key, ResultCallBack<CaptchaGetResponse<CheckCaptchaEntity>> callback){
        dataSource.checkCaptcha(sliderXMoved, token, key, callback);
    }

    public void captchacertExchange(String token, double sliderXMoved, String key, ResultCallBack<Result<CaptchaCertExchangeEntity>> callback){
        dataSource.captchaCertExchange(token, sliderXMoved, key, callback);
    }

    public void loginPhoneCode(String phone, String captcha_verification, ResultCallBack<Result<LoginEntity>> callBack){
        // String phone, String token, double sliderXMoved, String key
        dataSource.loginPhoneCode(phone, captcha_verification, callBack);
    }

    public void loginPhoneCodeCheck(String phone, String captcha_verification, String phone_code, ResultCallBack<Result<LoginEntity>> callBack){
        dataSource.loginPhoneCodeCheck(phone, captcha_verification, phone_code, callBack);
    }

    public void getQrCode(String vin, ResultCallBack<Result<QrLoginEntity>> callback){
        dataSource.getQrCode(vin, callback);
    }

    public void qrLoginPolling(String codeId, ResultCallBack<Result<QrLoginPollEntity>> callback){
        dataSource.qrLoginPolling(codeId, callback);
    }

    public void userPwdModify(String pwd, ResultCallBack<Result> callback){
        dataSource.userPwdModify(pwd, callback);
    }

    public void loginStatus(ResultCallBack<Result<LoginStatusEntity>> callback){
        dataSource.loginStatus(callback);
    }

    public void queryUserInfo(ResultCallBack<Result<UserInfoEntity>> callback){
        dataSource.queryUserInfo(callback);
    }

    public void updateUserInfo(UserInfoRequest request, ResultCallBack<Result> callback){
        dataSource.updateUserInfo(request, callback);
    }

    public void logout(String refresh_token, ResultCallBack<Result> callback){
        dataSource.logout(refresh_token, callback);
    }

}